{% extends "__data_browser__/list.html" %}
{% block __data_browser__customized_head_block %}
  {{ super() }}
  <script type="text/javascript">
    $(function () {
      $("[name=delete-button]").click(function () {
        btn = $(this);
        if (confirm("删除该待办事项吗？")) {
          btn.parents("form").submit();
        }
      });
    });
  </script>
{% endblock %}
{% block lists %}
  {% if __data__ %}
    <div class="panel-group container" id="accordion1">
      {% for grouper, list in __data__|groupby("create_date")|reverse %}
        {% if grouper == today %}
          {% set grouper = '今天' %}
        {% elif grouper == yesterday %}
          {% set grouper = '昨天' %}
        {% endif %}
        <div class="panel panel-default">
          <div class="panel-heading">
            <h4 class="panel-title">
              <a class="accordion-toggle" href="#{{ grouper }}" data-toggle="collapse" data-parent="#accordion1">
                {{ grouper }}<b>({{ list|length }})</b><i class="fa fa-chevron-up"></i>
              </a>
            </h4>
          </div>
          <div class="panel-collapse collapse" id="{{ grouper }}">
            <div class="panel-body">
              {% for todo in list %}
                <blockquote>
                  <form action="{{ url_for("todo.delete", id_=todo.id) }}" method="POST">
                    <button class="btn btn-link" name="delete-button" type="button">
                      <i class="fa fa-times text-danger"></i>
                    </button>
                    <span class="text-muted">
                      {{ todo.create_time.strftime("%H:%M") }}
                    </span>
                    {{ todo.msg }}
                    {% if todo.context_url %}
                      {% if "?" in todo.context_url %}
                        <a href="{{ todo.context_url + "&url=" + request.url|urlencode }}">开始&gt;&gt;</a>
                      {% else %}
                        <a href="{{ todo.context_url + "?url=" + request.url|urlencode }}">开始&gt;&gt;</a>
                      {% endif %}
                    {% endif %}
                  </form>
                </blockquote>
              {% endfor %}
            </div>
          </div>
        </div>
      {% endfor %}
    </div>
    {% from "__data_browser__/macro.html" import render_pagination %}
    {{ render_pagination(__pagination__, __count__, g.request_from_mobile) }}
  {% else %}
    <p class="alert alert-success">恭喜您！ 您的所有工作都完成了</p>
  {% endif %}
{% endblock %}
